//
//  CYXTabBarController.m
//   
//
//  Created by Macx on 15/9/4.
//  Copyright (c) 2015年 CYX. All rights reserved.
//

#import "CYXTabBarController.h"
#import "CYXOneViewController.h"
#import "CYXTwoViewController.h"
#import "CYXThreeViewController.h"
#import "CYXFourViewController.h"
#import "CYXNavigationController.h"
#import "WalletTabViewController.h"

@interface CYXTabBarController ()

@end

@implementation CYXTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];

    [self setUpAllChildViewController];
    


}

- (void)setupUI{
    [self.tabBar setBackgroundImage:[UIImage imageWithColor:LRRGBColor(37, 39, 52)]];
    self.tabBar.tintColor = [UIColor colorWithHexString:@"#935BFF"];
    self.tabBar.unselectedItemTintColor = [UIColor colorWithHexString:@"#5F658B"];
}

/**
 *  添加所有子控制器
 */
- (void)setUpAllChildViewController{
    // 1.添加第一个控制器
    BaseTableViewController *oneVC = [[BaseTableViewController alloc]init];
    oneVC.isIgnoreLogon = YES;
    [self setUpOneChildViewController:oneVC image:@"tab_homepage" title:LCLocalString(@"home") isClearNavBar:NO];
    
    // 2.添加第2个控制器
    BaseTableViewController *twoVC = [[BaseTableViewController alloc]init];
    oneVC.isIgnoreLogon = YES;
    [self setUpOneChildViewController:twoVC image:@"tab_app" title:LCLocalString(@"app") isClearNavBar:NO];
    
    // 3.添加第3个控制器
//    CYXThreeViewController *threeVC = [[CYXThreeViewController alloc]init];
//    [self setUpOneChildViewController:threeVC image:[UIImage imageNamed:@"qw"] title:@"博文"];
    
//    UIStoryboard *threeStoryBoard = [UIStoryboard storyboardWithName:@"CYXThreeViewController" bundle:nil];
//
//    CYXThreeViewController *threeVC = [threeStoryBoard instantiateInitialViewController];
    
    BaseTableViewController *threeVC = [[BaseTableViewController alloc]init];
    oneVC.isIgnoreLogon = YES;
 
    //    CYXFourViewController *fourVC = [[CYXFourViewController alloc]init];
    [self setUpOneChildViewController:threeVC image:@"tab_msg" title:LCLocalString(@"chats") isClearNavBar:NO];
    
    WalletTabViewController *wallet = [[WalletTabViewController alloc] init];
//    oneVC.isIgnoreLogon = YES;
 
    //    CYXFourViewController *fourVC = [[CYXFourViewController alloc]init];
    [self setUpOneChildViewController:wallet image:@"tab_qb" title:LCLocalString(@"wallet") isClearNavBar:YES];
    
    // 4.添加第4个控制器
//    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"CYXFourViewController" bundle:nil];
//
//    CYXFourViewController *fourVC = [storyBoard instantiateInitialViewController];
    CYXFourViewController *fourVC = [[CYXFourViewController alloc]init];

    [self setUpOneChildViewController:fourVC image:@"tab_profile" title:LCLocalString(@"me") isClearNavBar:YES];
}


/**
 *  添加一个子控制器的方法
 */
- (void)setUpOneChildViewController:(UIViewController *)viewController image:(NSString *)image title:(NSString *)title isClearNavBar:(BOOL)isClearBar{
    UIImage *img_n = [UIImage imageNamed:[NSString stringWithFormat:@"%@_g",image]];
    UIImage *img_s = [UIImage imageNamed:[NSString stringWithFormat:@"%@_p",image]];
    
    CYXNavigationController *navC = [[CYXNavigationController alloc]initWithRootViewController:viewController];
    navC.title = title;
    navC.tabBarItem.image = img_n;
    navC.tabBarItem.selectedImage = img_s;
    if (isClearBar) {
        [navC.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    }else{
        [navC.navigationBar setBackgroundImage:[UIImage imageWithColor:MainColor] forBarMetrics:UIBarMetricsDefault];
    }
    
    [navC.navigationBar setShadowImage:[[UIImage alloc]init]];
          
    viewController.navigationItem.title = title;
    
    [self addChildViewController:navC];
}





@end
